package com.cp.admin.modular.user.controller;

import com.cp.admin.modular.user.model.Chatgroup;
import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.user.service.IChatgroupService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2020-08-31 11:30:58
 */
@Controller
@RequestMapping("/chatgroup")
public class ChatgroupController extends BaseController {

    private String PREFIX = "/user/chatgroup/";

    @Autowired
    private IChatgroupService chatgroupService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "chatgroup.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/chatgroup_add")
    public String chatgroupAdd() {
        return PREFIX + "chatgroup_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/chatgroup_update/{chatgroupId}")
    public String chatgroupUpdate(@PathVariable Long chatgroupId, Model model) {
        Chatgroup chatgroup = chatgroupService.selectById(chatgroupId);
        model.addAttribute("item",chatgroup);
        LogObjectHolder.me().set(chatgroup);
        return PREFIX + "chatgroup_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return chatgroupService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Chatgroup chatgroup) {
        chatgroupService.insert(chatgroup);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long chatgroupId) {
        chatgroupService.deleteById(chatgroupId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Chatgroup chatgroup) {
        chatgroupService.updateById(chatgroup);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{chatgroupId}")
    @ResponseBody
    public Object detail(@PathVariable("chatgroupId") Long chatgroupId) {
        return chatgroupService.selectById(chatgroupId);
    }
}
